<?
	session_start();
	include('conn.php');
	$id = $_REQUEST["cud"];	
	$obj = json_decode($_REQUEST["dataset"]);	
	$cid = $obj->id;
	
	if($id=="d") //delete entry
	{		
		$cid = $_REQUEST["custid"];
		$qry = "update Customer set status='9' where CustId='$cid';";			
		$res = mysql_query($qry);
		echo $qry."---".$res;
	}
	else
	{						
		if($id=="u")  //update entry
		{
			$qry1 = "select socid from society where societyname='$obj->soc';";			
			$res1 = mysql_query($qry1);
			$row = mysql_fetch_array($res1);
			$sid = $row["socid"];
	
			$name = $obj->fname;
			if($obj->mname)
				$name .= " ".$obj->mname;					
			if($obj->lname)
				$name .= " ".$obj->lname;
				
			$qry = "update Customer set SAFno ='$obj->saf', socId='$sid',RoomNumber='$obj->room',firstname='$obj->fname',middlename='$obj->mname',lastname='$obj->lname',CustomerName='$name',Email='$obj->email',TelNo='$obj->phone',Notes='$obj->note',Floor='$obj->floor' where CustId='$cid';";			
			$res = mysql_query($qry);
			echo $qry1."---<br>".$qry."---".$res;						
		}
		else if($id=="c") //create new entry
		{
			$qry1 = "select socid from society where societyname='$obj->soc';";			
			$res1 = mysql_query($qry1);
			$row = mysql_fetch_array($res1);
			$sid = $row["socid"];
			
			$name = $obj->fname;
			if($obj->mname)
				$name .= " ".$obj->mname;					
			if($obj->lname)
				$name .= " ".$obj->lname;
					
			$qry = "insert into Customer(socId,RoomNumber,SAFno,firstname,middlename,lastname,CustomerName,Email,TelNo,Notes,Floor,status) values ('$sid','$obj->room','$obj->saf','$obj->fname','$obj->mname','$obj->lname','$name','$obj->email','$obj->phone','$obj->note','$obj->floor','1');";			
			$res = mysql_query($qry);
			echo $qry."---".$res;
		}
		else
			echo "ID not set";
	}
?>